


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html id="htmlId">
<head>
  <title>Coverage Report :: AssignablePredicate</title>
  <style type="text/css">
    @import "../../.css/coverage.css";
  </style>
</head>

<body>
<div class="header"></div>

<div class="content">
<div class="breadCrumbs">
    [ <a href="../../index.html">all classes</a> ]
    [ <a href="../index.html">at.dormancy.persister.predicate</a> ]
</div>

<h1>Coverage Summary for Class: AssignablePredicate (at.dormancy.persister.predicate)</h1>

<table class="coverageStats">
<tr>
  <th class="name">Class</th>
<th class="coverageStat 
">
  Class, %
</th>
<th class="coverageStat 
">
  Method, %
</th>
<th class="coverageStat 
">
  Line, %
</th>
</tr>
<tr>
  <td class="name">AssignablePredicate</td>
<td class="coverageStat">
  <span class="percent">
    100%
  </span>
  <span class="absValue">
    (1/ 1)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    100%
  </span>
  <span class="absValue">
    (4/ 4)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    100%
  </span>
  <span class="absValue">
    (11/ 11)
  </span>
</td>
</tr>

</table>

<br/>
<br/>


<div class="sourceCode"><i>1</i>&nbsp;/*
<i>2</i>&nbsp; * Copyright 2013 Gregor Schauer
<i>3</i>&nbsp; *
<i>4</i>&nbsp; * Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<i>5</i>&nbsp; * you may not use this file except in compliance with the License.
<i>6</i>&nbsp; * You may obtain a copy of the License at
<i>7</i>&nbsp; *
<i>8</i>&nbsp; *      http://www.apache.org/licenses/LICENSE-2.0
<i>9</i>&nbsp; *
<i>10</i>&nbsp; * Unless required by applicable law or agreed to in writing, software
<i>11</i>&nbsp; * distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
<i>12</i>&nbsp; * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<i>13</i>&nbsp; * See the License for the specific language governing permissions and
<i>14</i>&nbsp; * limitations under the License.
<i>15</i>&nbsp; */
<i>16</i>&nbsp;package at.dormancy.persister.predicate;
<i>17</i>&nbsp;
<i>18</i>&nbsp;import org.apache.commons.collections.Predicate;
<i>19</i>&nbsp;import org.apache.commons.lang.ArrayUtils;
<i>20</i>&nbsp;import org.springframework.util.ClassUtils;
<i>21</i>&nbsp;
<i>22</i>&nbsp;import javax.annotation.Nonnull;
<i>23</i>&nbsp;import javax.annotation.Nullable;
<i>24</i>&nbsp;import java.io.Serializable;
<i>25</i>&nbsp;
<i>26</i>&nbsp;/**
<i>27</i>&nbsp; * {@link Predicate} implementation that returns {@code true} if the input may be assigned to at least one of the types
<i>28</i>&nbsp; * stored in this {@link Predicate}.
<i>29</i>&nbsp; *
<i>30</i>&nbsp; * @author Gregor Schauer
<i>31</i>&nbsp; * @since 1.0.2
<i>32</i>&nbsp; */
<i>33</i>&nbsp;public class AssignablePredicate implements Predicate, Serializable {
<i>34</i>&nbsp;	protected Class&lt;?&gt;[] types;
<i>35</i>&nbsp;
<b class="fc"><i>36</i>&nbsp;	public AssignablePredicate(@Nullable Class&lt;?&gt;... types) {</b>
<b class="fc"><i>37</i>&nbsp;		this.types = types;</b>
<b class="fc"><i>38</i>&nbsp;	}</b>
<i>39</i>&nbsp;
<i>40</i>&nbsp;	/**
<i>41</i>&nbsp;	 * @return {@code true} if the parameter is assignable to at least one of the given types, {@code false} otherwise
<i>42</i>&nbsp;	 * @see ClassUtils#isAssignable(Class, Class)
<i>43</i>&nbsp;	 */
<i>44</i>&nbsp;	@Override
<i>45</i>&nbsp;	public boolean evaluate(@Nonnull Object object) {
<b class="fc"><i>46</i>&nbsp;		Class&lt;?&gt; clazz = object.getClass();</b>
<b class="fc"><i>47</i>&nbsp;		for (Class&lt;?&gt; supportedType : types) {</b>
<b class="fc"><i>48</i>&nbsp;			if (ClassUtils.isAssignable(supportedType, clazz)) {</b>
<b class="fc"><i>49</i>&nbsp;				return true;</b>
<i>50</i>&nbsp;			}
<i>51</i>&nbsp;		}
<b class="fc"><i>52</i>&nbsp;		return false;</b>
<i>53</i>&nbsp;	}
<i>54</i>&nbsp;
<i>55</i>&nbsp;	/**
<i>56</i>&nbsp;	 * Returns an array of the types used for testing.
<i>57</i>&nbsp;	 *
<i>58</i>&nbsp;	 * @return the types
<i>59</i>&nbsp;	 */
<i>60</i>&nbsp;	@Nonnull
<i>61</i>&nbsp;	public Class&lt;?&gt;[] getTypes() {
<b class="fc"><i>62</i>&nbsp;		return types != null ? types : ArrayUtils.EMPTY_CLASS_ARRAY;</b>
<i>63</i>&nbsp;	}
<i>64</i>&nbsp;
<i>65</i>&nbsp;	/**
<i>66</i>&nbsp;	 * Sets the types to use for testing.
<i>67</i>&nbsp;	 *
<i>68</i>&nbsp;	 * @param types the types
<i>69</i>&nbsp;	 */
<i>70</i>&nbsp;	public void setTypes(@Nullable Class&lt;?&gt;... types) {
<b class="fc"><i>71</i>&nbsp;		this.types = types;</b>
<b class="fc"><i>72</i>&nbsp;	}</b>
<i>73</i>&nbsp;}
</div>
</div>

<div class="footer">
    
    <div style="float:right;">generated on 2013-07-31 23:31</div>
</div>
</body>
</html>
